package com.league.zjxn.custom

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.DrawableRes
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.league.zjxn.R
import com.module.lemlin.http.HttpResponseBody
import com.module.lemlin.http.Status
import com.module.lemlin.http.msg
import com.scwang.smart.refresh.layout.SmartRefreshLayout


fun BaseQuickAdapter<*, BaseViewHolder>.setTransitionStatus(response: HttpResponseBody<*>) {
    when (response.status) {
        Status.START -> setEmptyView(
            createViewEmptyLoad(context, color = R.color.white)
        )
        Status.FAILURE -> setEmptyView(
            createViewEmptyNull(context, response.error?.msg, R.color.white)
        )
        Status.SUCCESS -> removeEmptyView()
    }
}

fun createViewEmptyNull(
    context: Context, hint: String? = null, @DrawableRes color: Int = android.R.color.transparent
): View = LayoutInflater.from(context).inflate(R.layout.view_empty_null, (null))
    .apply {
        layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        findViewById<TextView>(R.id.tvEmptyNullHint).text = hint
        setBackgroundResource(color)
    }

fun createViewEmptyLoad(
    context: Context, @DrawableRes color: Int = android.R.color.transparent
): View = LayoutInflater.from(context)
    .inflate(R.layout.view_empty_load, (null))
    .apply {
        layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        setBackgroundResource(color)
    }

//fun ViewGroup.setEmptyView(response: HttpResponseBody<*>){
//    when (response.status) {
//        Status.START -> removeView(mLoadingView).apply {
//            addView(
//                createViewEmptyLoad(context, color = R.color.white)
//            )
//        }
//        Status.FAILURE -> setEmptyView(
//            createViewEmptyNull(context, response.error?.msg, R.color.white)
//        )
//        Status.SUCCESS -> removeEmptyView()
//    }
//}